package biz.innovasoft.nodb.transaction;

import java.util.Collection;
import java.util.Date;

import org.prevayler.TransactionWithQuery;

import biz.innovasoft.nodb.impl.GenericRepository;

public class StoreTransaction implements TransactionWithQuery {

	private static final long serialVersionUID = 1L;
	
	private final Object data;
	private final int indexType;
	
	public StoreTransaction (Object data, int indexType) {
		this.data = data;
		this.indexType = indexType;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public Object executeAndQuery(Object prevalentSystem, Date time) throws Exception {
		GenericRepository repository = (GenericRepository)prevalentSystem;
		if (data instanceof Collection) {
			return (Long[])repository.store((Collection<?>)data, indexType);
		}
		return repository.store(data, indexType);
	}

}
